<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 10/16/14
 * Time: 11:23 AM
 */

namespace Library\Advertise;
use Phalcon\Mvc\User\Component;
use Common\Models\Videos\VideoPosterLink;

class Advertise extends Component
{

    public function getPosterHome()
    {
        $cacheKey = $this->constant->keyCache['videoPoster']['blockMastheadHome'];
        $sessionMasthead = $this->viewCache->get($cacheKey);
        if ($sessionMasthead === null) {
            //$this->view->setTemplateAfter('empty');
            $videoPosterLinks = VideoPosterLink::find();
            $videoPosterLinks = $this->modelsManager->createBuilder()
                ->from(array('videoPosterLink' => '\Common\Models\Videos\VideoPosterLink'))
                ->join('\Common\Models\Images\ImageLink' , 'imageLink.object_id = videoPosterLink.object_id' , 'imageLink')
                ->groupBy("videoPosterLink.id")
                ->limit(500)
                ->where('imageLink.type = :type: AND videoPosterLink.status = :status:' , array('type' => 'C' , 'status' => 'A'))
                ->orderBy('videoPosterLink.position')
                ->getQuery()
                ->execute();
                
            $this->view->videoPosterLinks = $videoPosterLinks;
            $sessionMasthead = $this->view->getRender("masthead" , "home/poster" , array('videoPosterLinks' => $videoPosterLinks));
            $this->viewCache->save($cacheKey, $sessionMasthead);
        }
        return $sessionMasthead;
    }

} 